import { getGoodsOnlineCategory } from "@/api/pointsMall";
import { useMallConfig } from "@/views/pointsMall/compositions/useMallConfig";


/**
 * 获取商品分类选项
 */
export function useGetGoodsCategory() {
  const store = useStore()

  const goodsCateList = computed(() => store.state.pointsMall.goodsCateList)

  const getGoodsCate = async (mallId?: number) => {
    let _mallId: number
    if (!mallId) {
      const { mallConfig } = useMallConfig()
      _mallId = mallConfig.value.id
    } else {
      _mallId = mallId
    }
    
    const rs = await getGoodsOnlineCategory({ id: _mallId })
    store.commit('pointsMall/updateGoodsCateList', rs.payload ?? [])
  }

  return {
    goodsCateList,
    getGoodsCate,
  }
}
